﻿using System.Collections.ObjectModel;
using System.Linq;
using DataLayer.Types;

namespace ViewModel.Aggregators
{
    public static class AggregateTools
    {
        public static decimal CalculateBudgetItemPeriodPayment(decimal budgetAmount, decimal budgetFrequency, decimal paymentPeriod)
        {
            return (budgetAmount*(budgetFrequency/paymentPeriod));
        }

        public static decimal CalculateTotalPeriodicPayment(ObservableCollection<BudgetItem> budgetItems, FrequencyItem frequencyItem, 
            BalanceType balanceType)
        {
            decimal result = 0;
//            var theOnes =
//                from items in budgetItems
//                where items.BalanceType.Id == balanceType.Id && items.Active == true
//                select items;

//            foreach (BudgetItem item in theOnes)
//            {
//                result += CalculateBudgetItemPeriodPayment(item.Amount, item.Frequency.ValuePerYear, frequencyItem.ValuePerYear);
//            }

            foreach (BudgetItem budgetItem in budgetItems)
            {
                if(budgetItem.Active && budgetItem.BalanceType.Equals(balanceType))
                {
                    result += CalculateBudgetItemPeriodPayment(budgetItem.Amount, budgetItem.Frequency.ValuePerYear, frequencyItem.ValuePerYear);
                }
            }

            return result;
        }
    }
}
